package gui;

import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.*;

import test.Main;
import model.getDate;

public class MainScreen extends JFrame implements ActionListener 
{
	private static final long serialVersionUID = 1L;
	private JPanel panel1, p1a,p1b, p1c, panel2, t1, t2, t3, t4, t5, t6, t7;
	private JLabel welcome, date;
	private JButton logout, addOrder;
	private JTabbedPane tp;
	private JMenuBar menuBar;
	private JMenu file, help;
	
	public MainScreen() 
	{
		super("MainScreen");
		this.setSize(840, 500);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setLayout(new FlowLayout());
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		
		//Menu Bar
		menuBar = new JMenuBar();
		file = new JMenu("File");
		file.setMnemonic(KeyEvent.VK_A);
		menuBar.add(file);
		
		//help menu
		help = new JMenu("Help");
		menuBar.add(help);
		this.setJMenuBar(menuBar);
		
		//Panels
		panel1 = new JPanel();
		panel2 = new JPanel();
		
		//Adding Panels to frame
		this.add(panel1, BorderLayout.NORTH);
		this.add(panel2, BorderLayout.SOUTH);
		
		//Panel 1
		panel1.setLayout(new BorderLayout());
		panel1.setPreferredSize(new Dimension(830, 100));
		
		//panel 1a
		p1a = new JPanel();
		p1a.setPreferredSize(new Dimension(260, 100));
		
		ImageIcon logo = new ImageIcon("src/files/logo2.png");		
		JLabel milkrun = new JLabel(logo);
		
		
		
        p1a.add(milkrun); 
		//panel 1b
        p1b = new JPanel();
        p1b.setPreferredSize(new Dimension(460, 100));
		welcome = new JLabel("Welcome "+Main.username);
		
		date = new JLabel(getDate.date());
		p1b.add(welcome); 
		p1b.add(Box.createRigidArea(new Dimension(100,0)));
		p1b.add(date); 
	
		logout = new JButton("   LOGOUT   ");
		logout.addActionListener(this);
		
       
        
		//Panel 1c
		p1c = new JPanel();
		p1c.setPreferredSize(new Dimension(110, 100));
		addOrder = new JButton("ADD ORDER");
		addOrder.addActionListener(this);
		p1c.add(logout); 
        p1c.add(addOrder); 
        //adding panels to panel 1 !
        panel1.add(p1a, BorderLayout.WEST);
        panel1.add(p1b, BorderLayout.CENTER);
        panel1.add(p1c, BorderLayout.EAST);
	
        
        //t1 = new tab1();			
       // t2 = new tab2();
        //t3 = new tab3();
       // t4 = new tab4();
       // t5 = new tab5();
        t6 = new tab6();
        t7 = new tab7();
        
        //TabbedPane
        panel2.setPreferredSize(new Dimension(800, 330));
        tp = new JTabbedPane();
        tp.addTab("Daily Orders", t1);
    	tp.addTab("Estate", t2);
    	tp.addTab("Invoice", t3);
    	tp.addTab("Customer", t4);
    	tp.addTab("Order", t5);
    	tp.addTab("Product", t6);
    	tp.addTab("Statistics", t7);
    	panel2.add(tp , BorderLayout.CENTER);
	}
	
		public JComponent makeTextPanel(String text) 
		{
			JPanel panel = new JPanel(false);
			JLabel filler = new JLabel(text);
			filler.setHorizontalAlignment(JLabel.CENTER);
			panel.setLayout(new GridLayout(1, 1));
			panel.add(filler);
			return panel;
		}
     
		public static void main(String args[]) 
		{
			MainScreen ms = new MainScreen();
			ms.setVisible(true);
		}

		@Override
		public void actionPerformed(ActionEvent ae)
		{
			if(ae.getSource()==addOrder)
			{
				addOrderGUI ao = new addOrderGUI();
				ao.setVisible(true);
			}
			if(ae.getSource()==logout)
			{
				this.dispose();
				loginGUI ls = new loginGUI();
				ls.setVisible(true);
			}
		}
}
